import { onBeforeUnmount, onMounted } from 'vue';
import mitt, { type Emitter } from 'mitt';

const emitter: Emitter<any> = mitt();

export const useEmitter = (event, handler) => {
  onMounted(() => {
    emitter.on(event, handler);
  });

  onBeforeUnmount(() => {
    emitter.off(event, handler);
  });
};
